package com.tiancheng.trade.merchant.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author kellen
 * @date 2021/7/22
 */
@Getter
@AllArgsConstructor
public enum MerchantPayChannelUsedEnum {
    USED(1, "被使用"),
    NOT_USED(0, "未被使用"),
    ;

    private final Integer code;
    private final String desc;

    public static String getDescByCode(Integer code) {
        return Arrays.stream(values()).filter(d -> Objects.equals(d.getCode(), code)).findFirst()
                .map(MerchantPayChannelUsedEnum::getDesc).orElse("");
    }

    /**
     * 根据code获取具体枚举，一般switch中使用
     *
     * @param code
     * @return
     */
    public static MerchantPayChannelUsedEnum getByCode(Integer code) {
        return Arrays.stream(values()).filter(d -> Objects.equals(d.getCode(), code)).findFirst().orElse(null);
    }

}
